<template>
  <div class="more-container">
    <el-row>
      <el-col>
        <!--     <el-button type="primary" @click='additem'>新增</el-button> -->
      </el-col>
      <commonline :newText="'机构'" @addList="additem" @refreshData="refreshData" :importname="'机构'" :showRight="false"
        :isshowImport="teamType != 4 && checkPermission(['schoolTeamImport'])" :isshowAdd="checkPermission(['schoolTeamAdd'])"
        :importUrl="'school/team/import'" :dUrl="'https://oss.juchehulian.com/Excel/%E6%9C%BA%E6%9E%84%E5%AF%BC%E5%85%A5%E6%A8%A1%E6%9D%BF.xls'"></commonline>

      <el-col :span="24">
        <div class="content">

          <!-- <el-col :span="8">
            <div class="left">
              <p class="title" @click="getschoolteamread(allId)">{{ title }} </p>
              <el-tree class="jgTree" :data="treeData" :props="props" :expand-on-click-node="true" @node-click="handleNodeClick">
                <span class="custom-tree-node" slot-scope="{ node, data }">
                  <span>
                    <span class="active">{{ node.label }}</span>
                    <span v-if="data.totalChildren>1">（{{data.totalChildren}}）</span>
                    <el-tag type="success" v-if="data.isBranch == 1" style="margin-left: 0.3rem">
                      服务点
                    </el-tag>
                  </span>

                  <span>
                    <el-tooltip content="审核中" placement="top" v-if="data.status == 0">
                      <span class="statusTips yellow"></span>
                    </el-tooltip>
                    <el-tooltip content="已通过" placement="top" v-if="data.status == 1">
                      <span class="statusTips green"></span>
                    </el-tooltip>
                    <el-tooltip placement="top" v-if="data.status == 2">
                      <div slot="content">驳回（{{ data.backInfo }})</div>
                      <span class="statusTips red"></span>
                    </el-tooltip>
                    <el-tooltip content="线上状态" placement="top">
                      <el-switch :disabled="!checkPermission(['schoolTeamShow'])" v-if="teamType == 1" v-model="data.state"
                        :active-value="1" :inactive-value="0" @change="goSchoolteamupdateState(data.state, data.id)"
                        @click.stop.native></el-switch>
                    </el-tooltip>

                    <span style="
                        width: 6rem;
                        display: inline-block;
                        text-align: right;
                        margin-left: 0.5rem;
                      ">
                      <el-tooltip content="权限设置" placement="top">
                        <el-button class="el-icon-editBox" :type="
                           !checkPermission(['schoolTeamSetting']) || teamType>=data.type
                              ? 'info'
                              : 'primary'
                          "
                          size="mini" icon="el-icon-s-tools" circle :disabled="!checkPermission(['schoolTeamSetting']) || teamType>=data.type"
                          @click.stop="() => roleEdit(data)"></el-button>
                      </el-tooltip>
                      <el-tooltip content="审核" placement="top" v-if="data.approvalTeam == teamId && data.status == 0 && checkPermission(['schoolTeamApproval'])">
                        <el-button class="el-icon-editBox" type="primary" size="mini" icon="el-icon-s-check" circle
                          @click.stop="() => showExamine(data)"></el-button>
                      </el-tooltip>
                      <el-tooltip content="审核" placement="top" v-else>
                        <el-button class="el-icon-editBox" type="info" size="mini" icon="el-icon-s-check" circle
                          disabled></el-button>
                      </el-tooltip>
                      <el-tooltip content="删除" placement="top">
                        <el-button class="el-icon-deleteBox" :type="
                            teamRelation.indexOf(data.id) == -1 ||
                            data.id == teamId || !checkPermission(['schoolTeamDelete'])
                              ? 'info'
                              : 'danger'
                          "
                          size="mini" icon="el-icon-delete" circle :disabled="
                            data.id == teamId ||
                            teamRelation.indexOf(data.id) == -1
                            || !checkPermission(['schoolTeamDelete'])
                          "
                          @click.stop="() => delite(data)"></el-button>
                      </el-tooltip>
                    </span>
                  </span>
                </span>
              </el-tree>
            </div>
          </el-col>
          -->
          <el-col :span="24">
            <!-- <div class="formarea" ref="element">

              <el-form
                ref="allform"
                size="medium"
                :rules="rules"
                :model="form"
                label-width="120px"
                :disabled="showFormBtn || !checkPermission(['schoolTeamEdit'])"

              >
               <el-row>
                  <el-col :span="12">
                    <el-form-item :label="form.parent_id?'上级机构':'当前机构'" prop="parent_id" >
                      <treeselect
                        style="width: 100%"
                        v-model="form.parent_id"
                        :options="treeOptions"
                        :default-expand-level="1"
                        :normalizer="normalizer"
                        placeholder="请选择上级机构"
                        v-if="parent_idTitle==''"
                      />
                      <el-input
                         v-else
                        v-model="parent_idTitle"
                        clearable
                        disabled
                      ></el-input>
                    </el-form-item>

                  </el-col>
                   <el-col :span="12">
                    <el-form-item
                      :label="'封\u2000面\u2000图'"
                      prop="head_img"
                      :disabled="true"
                    >
                      <uploader
                        :initUrl="form.head_img"
                        @uploadimgok="head_imgok"
                        @deleteimg="head_imgdel"
                         class="pos"
                      >
                        <span slot="text">
                          支持上传不大于10M的JPEG、JPG、PNG、BMP图片
                        </span>
                      </uploader>
                    </el-form-item>
                  </el-col>
                </el-row>
                   <el-row>
                  <el-col :span="12">
                    <el-form-item label="机构类型" prop="type">
                      <el-select
                        v-model="form.type"
                        clearable
                        placeholder="请选择机构类型"
                        style="width: 100%"
                        @change="changeType"
                        :disabled="form.type == 1"
                      >
                        <el-option
                          v-for="item in typeOption"
                          :key="item.val"
                          :label="item.title"
                          :value="item.val"
                          :disabled="item.disabled"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>

                </el-row>

                <el-row>
                  <el-col :span="12">
                    <el-form-item label="机构名称" prop="title">
                      <el-input
                        v-model="form.title"
                        placeholder="请输入机构名称"
                        clearable
                        :disabled="type == 1"
                      ></el-input>
                    </el-form-item>

                  </el-col>
                   <el-col :span="12">
                    <el-form-item
                      :label="'详\u2000情\u2000图'"
                      prop="picture"
                      :disabled="true"
                    >
                      <uploader
                        :initUrl="form.picture"
                        @uploadimgok="pictureok"
                        @deleteimg="picturedel"
                        :fixedNumber="[2, 1]"
                        class="pos"
                      >
                        <span slot="text">
                          支持上传不大于10M的JPEG、JPG、PNG、BMP图片
                        </span>
                      </uploader>
                    </el-form-item>
                  </el-col>
                </el-row>



                <el-row>
                  <el-col :span="12">
                    <el-form-item prop="nickname" :label="'联\u2000系\u2000人'">
                      <el-input
                        v-model="form.nickname"
                        clearable
                        placeholder="请输入联系人"
                        :disabled="type == 1"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="联系电话" prop="tel">
                      <el-input
                        v-model="form.tel"
                        clearable
                        placeholder="请输入联系电话"
                        disabled
                      ></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="选择城市" prop="city">
                      <el-cascader
                        size="large"
                        clearable
                        placeholder="请选择城市"
                        :options="options"
                        v-model="form.city"
                        :show-all-levels="true"
                        @change="changeArea"
                        :disabled="type == 1"
                        style="width: 100%"
                      ></el-cascader>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="运营方式" prop="is_partner">
                      <el-radio-group
                        v-model="form.is_partner"
                        :disabled="type == 1"
                      >
                        <el-radio :label="0">直营</el-radio>
                        <el-radio :label="1">加盟</el-radio>
                      </el-radio-group>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="服务网点" prop="is_branch">
                        <el-radio-group v-model="form.is_branch">
                          <el-radio :label="1" :disabled="form.type == 4">
                            是
                          </el-radio>
                          <el-radio :label="0">否</el-radio>
                        </el-radio-group>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-col :span="12">
                    <el-form-item
                      label="基础设施"
                      prop="facilities"
                      :hide-required-asterisk="false"
                    >
                      <el-checkbox-group
                        v-model="form.facilities"
                        size="medium"
                      >
                        <el-checkbox
                          v-for="(item, index) in facilitiesOption"
                          :key="index"
                          :label="item.id"
                          :disabled="item.disabled"
                        >
                          {{ item.title }}
                        </el-checkbox>
                      </el-checkbox-group>
                    </el-form-item>
                  </el-col>
                </el-row>

                <el-row>
                  <el-col :span="12">
                    <el-form-item label="机构地址" prop="address">
                      <el-input
                        placeholder="请点击右边选择地图来选择地址"
                        :validate-event="false"
                        :disabled="true"
                        v-model="form.address"
                      >
                        <template slot="append">
                          <el-button @click="selectmap">选择地图</el-button>
                        </template>
                      </el-input>
                    </el-form-item>
                    <mapDialog
                      v-if="isshowmap"
                      :isshowmapDialog="isshowmap"
                      @closemap="closemap"
                      @affirmMaps="affirmMap"
                      :userSelectinfo="selectmapinfo"
                    ></mapDialog>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col>
                    <el-form-item>
                      <el-button type="primary" @click="submitForm('allform')">
                        确定
                      </el-button>
                      <el-button @click="resetForm">重置</el-button>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form>
            </div>
          -->
            <el-table :data="tableData" style="width: 100%;margin-top: 30px;" row-key="id" border default-expand-all
              :tree-props="{children: 'children'}">
              <el-table-column prop="title" label="机构名称" show-overflow-tooltip align="center" width="250">
                <template slot-scope='scope'>
                  <span>{{scope.row.title}}</span>
                  <span v-if="scope.row.children &&scope.row.children.length>1">（{{scope.row.children.length}}）</span>
                  <el-tag type="success" v-if="scope.row.id == teamId" style="margin-left: 0.3rem">
                    当前机构
                  </el-tag>
                </template>
              </el-table-column>
              <el-table-column prop="type.title" label="机构类型" align="center">
              </el-table-column>
              <el-table-column prop="city.title" label="所在城市" align="center">
              </el-table-column>
              <el-table-column prop="operator.nickname" label="负责人" align="center">
              </el-table-column>
              <el-table-column prop="operator.tel" label="联系电话" align="center">
              </el-table-column>
              <el-table-column prop="address" label="机构地址" show-overflow-tooltip align="center">
              </el-table-column>
              <el-table-column prop="is_branch" label="是否服务网点" align="center">
                <template slot-scope='scope'>
                  <span v-if="scope.row.is_branch==1">是</span>
                  <span v-else>-</span>
                </template>
              </el-table-column>
              <el-table-column prop="status.title" label="审核状态" align="center">
                <template slot-scope='scope'>
                  <span v-if="scope.row.status.value==2" style="color:#F56C6C ;">{{scope.row.status.title}} <span style="color:#909399 ;">
                      ({{scope.row.status.teamType!='-'?scope.row.status.teamType:''}}) </span></span>
                  <span v-else-if="scope.row.status.value==0" style="color:#ff851a ;">{{scope.row.status.title}} <span
                      style="color:#909399 ;"> ({{scope.row.status.teamType!='-'?scope.row.status.teamType:''}}) </span></span>
                  <span v-else>{{scope.row.status.title}}</span>
                </template>
              </el-table-column>
              <el-table-column prop="state" label="线上状态" align="center">
                <template slot-scope='scope'>
                  <el-switch :disabled="!checkPermission(['schoolTeamShow']) && teamType != 1" v-model="scope.row.state"
                    :active-value="1" :inactive-value="0" @change="goSchoolteamupdateState(scope.row.state, scope.row.id)"
                    @click.stop.native></el-switch>
                </template>
              </el-table-column>
              <el-table-column prop="create_user.creator" label="创建人" align="center">
                <template slot-scope='scope'>
                  <span>
                    {{scope.row.create_user.creator}} <span v-if="scope.row.create_user.type!='-'">({{scope.row.create_user.type}})</span>
                  </span>
                </template>
              </el-table-column>
              <el-table-column prop="" label="操作" align="center" fixed="right" width="200">
                <template slot-scope='scope'>
                  <el-button type="text" class="tableButton" @click="editFrom(scope.row)" :disabled="teamRelation.indexOf(scope.row.id) == -1 || !checkPermission(['schoolTeamEdit'])">编辑</el-button>
                  <el-button type="text" class="tableButton" :disabled="!checkPermission(['schoolTeamSetting']) || teamType>=scope.row.type.value"
                    @click="roleEdit(scope.row)">权限设置</el-button>
                  <el-button type="text" class="tableButton" :disabled="!(scope.row.approval_team == teamId && scope.row.status.value == 0 && checkPermission(['schoolTeamApproval']))"
                    @click="showExamine(scope.row)">审核</el-button>
                  <el-button type="text" class="tableButton" :disabled="
                           scope.row.id == teamId ||
                           teamRelation.indexOf(scope.row.id) == -1
                           || !checkPermission(['schoolTeamDelete'])
                         "
                    @click.stop="delite(scope.row)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-col>
        </div>
      </el-col>
    </el-row>
    <!-- 权限框 -->
    <jurisdictionDialog ref="jurisdictionDialog" @confirm="confirm" :isshowDialog="isshowjurisdictionDialog" :dialogTitle="dialogtitle"
      @closedialog="closedialog"></jurisdictionDialog>
    <!-- 弹窗 -->
    <agencydialog :options="options" :formTypejg="formTypejg" :isshowDialog="isshowDialog" :dialogTitle="dialogtitle"
      @confirm="confirm" @closedialog="closedialog"></agencydialog>
    <toExamine :paramsId="currentId" :isshowDialog="isshowDialogtoExamine" :dialogTitle="dialogTitleExamine" @confirm="confirmtoExamine"
      @closedialog="closedialogtoExamine"></toExamine>
  </div>
</template>

<script>
//引入通用行
import commonline from '@/components/commonline/commonline'
//弹窗外壳
import commonformdialog from '@/components/commondialog/commondialog'
//地图弹窗组件
import jurisdictionDialog from './component/jurisdictionDialog'
import mapDialog from '@/components/selectmap/selectmap'
//引入图片上传组件
//按钮权限验证
import checkPermission from '@/utils/permission'
import uploadimg from '@/components/uploadimg/uploadimg'
import uploader from '@/components/uploadImgNew/uploadImgNew'
import {
  schoolteam,
  schoolteamread,
  schoolteamdelete,
  schoolteamupdate,
  schoolteamupdateState,
} from '@/api/school'
//api
import { getArea, Optionall } from '@/api/common'

import { getUserInfo } from '@/api/user'
import { getSessionStorage } from '@/utils/accessToken'
import Treeselect from '@riophae/vue-treeselect' //下拉树组件
import agencydialog from './component/agencydialog'
import toExamine from './component/toExamine'
export default {
  data() {
    return {
      //新增还是编辑
      treeOptions: [],
      tableData: null,
      isshowDialogtoExamine: false,
      formTypejg: 0,
      teamType: '',
      //是否显示弹窗
      isshowDialog: false,
      //弹窗标题
      dialogtitle: '新增',
      //地区选项
      options: [],
      form: {
        nickname: '',
        parent_id: '',
        tel: '',
        type: '',
        title: '',
        is_branch: '',
        is_partner: '',
        state: '',
        status: '',
        address: '',
        head_img: '',
        city: 0,
        picture: '',
        facilities: [],
      },
      rules: {
        parent_id: [],
        title: [
          {
            required: true,
            message: '请输入机构名称',
            trigger: 'change',
          },
        ],
        type: [
          {
            required: true,
            message: '请至少选择一个类型',
            trigger: 'change',
          },
        ],
        nickname: [
          {
            required: true,
            message: '请输入联系人',
            trigger: 'change',
          },
        ],

        tel: [
          {
            required: true,
            message: '请输入手机号',
            trigger: 'change',
          },

          {
            pattern: /^1\d{10}$/,
            message: '手机号有误',
            trigger: 'change',
          },
        ],
        city: [
          {
            required: true,
            message: '请选择城市！',
            trigger: 'change',
          },
        ],
        is_branch: [
          {
            required: true,
            message: '请选择服务网点！',
            trigger: 'change',
          },
        ],
        is_partner: [
          {
            required: true,
            message: '请选择运营方式！',
            trigger: 'change',
          },
        ],
        // facilities: [
        //   {
        //     required: true,
        //     message: '请选择基础设施！',
        //     trigger: 'blur',
        //   },
        // ],
        // head_img: [
        //   {
        //     required: true,
        //     message: '请上传封面图',
        //     trigger: 'change',
        //   },
        // ],
        // picture: [
        //   {
        //     required: true,
        //     message: '请上传详情图',
        //     trigger: 'change',
        //   },
        // ],

        // address: [
        //   {
        //     required: true,
        //     message: '请选择地址',
        //     trigger: 'change',
        //   },
        // ],
      },
      typeOption: [
        {
          title: '总校',
          val: 1,
        },
        {
          title: '分校',
          val: 2,
        },
        {
          title: '报名点',
          val: 3,
        },
        {
          title: '教练团队',
          val: 4,
        },
      ],
      //用户选择的地图
      selectmapinfo: {},
      props: {
        label: 'title',
        children: 'children',
      },
      treeData: [],
      facilitiesOption: [],
      title: '',
      isshowmap: false,
      allId: '', //总校id
      currentId: '',
      teamId: '',
      teamRelation: [],
      showFormBtn: false,
      dialogTitleExamine: '机构审核',
      token: '',
      height: 0,
      type: '',
      isshowjurisdictionDialog: false,
      currentRule: [],
      parent_idTitle: '',
    }
  },

  components: {
    agencydialog,
    //地图选择组件
    mapDialog,
    //上传图片组件
    uploadimg,
    uploader,
    toExamine,
    Treeselect,
    commonline,
    jurisdictionDialog,
  },
  methods: {
    checkPermission,
    changeparent_id(val, i) {
      this.typeOption.forEach((item) => {
        if (item.val > val.type) {
          item.disabled = false
        } else {
          item.disabled = true
        }
      })
    },
    //编辑权限
    roleEdit(val) {
      this.dialogtitle = '编辑权限-' + val.title
      this.getschoolteamread(val.id).then(() => {
        let params = {
          id: val.id,
          currentRule: this.currentRule,
        }
        this.isshowjurisdictionDialog = true
        this.$refs.jurisdictionDialog.getaccountRuleTree(params)

      })
  
    },
    refreshData() {
      //刷新列表
      this.getschoolteam()
    },
    normalizer(node) {
      return {
        id: node.id,
        label: node.title,
        children: node.children,
      }
    },
    //treeclick
    handleNodeClick(data) {
      this.currentId = data.id
      this.getschoolteamread(data.id)
    },
    changeType(e) {
      this.heightNow()
    },
    //切换机构类型
    async goSchoolteamupdateState(val, id) {
      let state = val ? 0 : 1
      let params = {
        id: id,
        state: state,
      }
      let data = await schoolteamupdateState(params)
      if (data.code == '0000') {
        this.$message({
          type: 'success',
          message: '修改成功!',
        })
      } else {
        this.getschoolteam()
      }
    },
    //判断
    isDisabled(val) {
      return val.indexOf(this.teamRelation) == -1
    },
    //列表
    async getschoolteam() {
      let info = await getUserInfo()
      let data = await schoolteam()
      let datas = await Optionall()
      if (datas.code == '0000') {
        window.sessionStorage.setItem('Optionsall', JSON.stringify(datas.data))
      }
      this.tableData = data.data
      this.facilitiesOption = getSessionStorage('Options')[20]
      this.teamRelation = info.data.teamRelation
      this.teamType = info.data.teamType
      this.teamId = info.data.teamId
      this.treeOptions = getSessionStorage('Optionsall').team
      this.typeOption.forEach((item) => {
        if (item.val > this.teamType) {
          item.disabled = false
        } else {
          item.disabled = true
        }
      })
    },
    async editFrom(val) {
      this.isshowDialog = true
      this.formTypejg = 1
      this.dialogtitle = '编辑机构-'+val.title
      await this.getschoolteamread(val.id)
      let params = {
        selectmapinfo: this.selectmapinfo,
        form: this.form,
      }
      this.$bus.emit('editFrom', params)
    },
    //选择地区触发
    changeArea(val) {
      this.form.city = val[val.length - 1]
      console.log(this.form.city)
    },
    //获取地区选项
    async getAreaOption() {
      let data = await getArea()
      this.options = data.data
    },
    //详情
    async getschoolteamread(id) {
      let data = await schoolteamread({
        id: id,
      })
      this.form = Object.assign({}, data.data)
      if (data.data.rule) {
        this.currentRule = data.data.rule
      }
      // this.form =data.data
      ;(this.form.facilities = data.data.facilities
        ? data.data.facilities.split(',').map(Number)
        : []),
        (this.form.address = data.data.address)
      this.form.lat = data.data.lat
      this.form.lng = data.data.lng
      this.type = data.data.type.value
      this.form.type = data.data.type.value
      this.form.picture = data.data.picture
      this.form.head_img = data.data.head_img
      this.form.city = data.data.city.value
      this.form.parent_id =
        data.data.parent_id.value == 0 ? null : data.data.parent_id.value
      let parent_idTitle = ''
      if (data.data.parent_id.value == 0) {
        parent_idTitle = data.data.title
      } else if (this.teamRelation.indexOf(data.data.parent_id.value) == -1) {
        parent_idTitle = data.data.parent_id.title
      } else {
        parent_idTitle = ''
      }
      this.form.parent_idTitle = parent_idTitle
      this.treeOptions = getSessionStorage('Optionsall').team
      if (data.data.type == 1) {
        this.treeOptions.forEach((item) => {
          item.isDisabled = true
        })
        console.log(this.treeOptions)
      } else {
        this.treeOptions.forEach((item) => {
          item.isDisabled = false
        })
      }

      let { address, lat, lng } = data.data
      if (address && lat && lng) {
        this.selectmapinfo = {
          address,
          lat,
          lng,
        }
      }
    },
    //重置
    async resetForm() {
      if (this.currentId == '') {
        return
      }
      this.getschoolteamread(this.currentId)
    },
    //删除图片
    head_imgdel() {
      this.form.head_img = ''
    },
    //上传图片成功
    head_imgok(imgUrl) {
      console.log(imgUrl)
      this.form.head_img = imgUrl
    },
    //删除图片
    picturedel() {
      this.form.picture = ''
    },
    //上传图片成功
    pictureok(imgUrl) {
      console.log(imgUrl)
      this.form.picture = imgUrl
    },
    //新增成功
    confirm() {
      this.isshowDialog = false
      this.isshowjurisdictionDialog = false

      //刷新列表
      this.getschoolteam()
    },
    //点击打开审核弹窗
    showExamine(val) {
      this.isshowDialogtoExamine = true
      this.$bus.emit('getparamsId', val.id)
    },
    //点击关闭审核弹窗
    closedialogtoExamine() {
      this.isshowDialogtoExamine = false
    },
    //确认审核成功
    confirmtoExamine() {
      this.isshowDialogtoExamine = false
      //刷新列表
      this.getschoolteam()
    },
    //点击打开弹窗
    additem() {
      this.isshowDialog = true
      this.formTypejg = 0
      this.dialogtitle = '新增机构'
    },
    //获取表单高度更新
    heightNow() {
      let height = this.$refs.element.offsetHeight + 'px'
      this.height = height
      console.log(height)
    },
    //选择地图
    selectmap() {
      let mapObj = {}
      this.isshowmap = true
    },
    //关闭地图
    closemap() {
      this.isshowmap = false
    },
    //确定选择地图
    affirmMap(params) {
      this.selectmapinfo = params
      this.form.address = params.address
      this.form.lat = params.lat
      this.form.lng = params.lng
      this.isshowmap = false
    },
    //删除
    delite(e) {
      this.$confirm('确定删除该机构, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(async () => {
          let data = await schoolteamdelete({
            id: e.id,
          })
          if (data.code == '0000') {
            this.$message({
              type: 'success',
              message: '删除成功!',
            })
            this.getschoolteam()
          }
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除',
          })
        })
    },
    //关闭弹窗
    closedialog() {
      this.formTypejg = 0
      this.isshowDialog = false
      this.isshowjurisdictionDialog = false
    },
    //编辑机构
    async goschoolteamupdate() {
      let params = {
        nickname: this.form.nickname,
        tel: this.form.tel,
        type: this.form.type,
        title: this.form.title,
        is_branch: this.form.is_branch,
        is_partner: this.form.is_partner,
        state: this.form.state,
        status: this.form.status.value,
        address: this.form.address,
        head_img: this.form.head_img,
        city: this.form.city,
        parent_id: this.form.parent_id ? this.form.parent_id : 0,
        picture: this.form.picture,
        lng: this.form.lng,
        lat: this.form.lat,
        id: this.form.id,
        facilities: this.form.facilities.join(','),
      }

      let data = await schoolteamupdate(params)
      if (data.code == '0000') {
        this.$message({
          type: 'success',
          message: data.msg,
        })
        this.isshowDialog = false
        this.isshowjurisdictionDialog = false
        //刷新列表
        this.getschoolteam()
      }
    },
    //提交
    submitForm(formName) {
      if (this.form.is_branch == 1) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.goschoolteamupdate()
          } else {
            console.log('error submit!!')
            return false
          }
        })
      } else {
        let arr = ['title', 'type', 'nickname', 'tel', 'city', 'is_branch']
        if (this.form.parent_id) {
          arr.push('is_partner')
        }
        let num = 0
        this.$refs[formName].validateField(arr, (error) => {
          if (error) {
            return false
          } else {
            num++
          }
        })
        console.log(num, '1111111111111')
        if (num == arr.length) {
          this.goschoolteamupdate()
        }
      }
    },
  },
  created() {
    //基础设施选项
    this.getAreaOption()
    this.getschoolteam()
  },
  mounted() {
    this.$nextTick(() => {
      this.heightNow()
    })
  },

  watch: {
    'form.type': function (val) {
      if (val == 4) {
        this.form.is_branch = 0
      }
      if (val == 2) {
        this.rules.title = [
          {
            required: true,
            message: '请输入机构名称',
            trigger: 'change',
          },
          {
            pattern: /分校$/,
            message: '必须以“分校”结尾',
            trigger: 'blur',
          },
        ]
      } else if (val == 3) {
        this.rules.title = [
          {
            required: true,
            message: '请输入机构名称',
            trigger: 'change',
          },
          {
            pattern: /报名点$/,
            message: '必须以“报名点”结尾',
            trigger: 'blur',
          },
        ]
      } else if (val == 4) {
        this.rules.title = [
          {
            required: true,
            message: '请输入机构名称',
            trigger: 'change',
          },
          {
            pattern: /团队$/,
            message: '必须以“团队”结尾',
            trigger: 'blur',
          },
        ]
      }
    },
    'form.parent_id': function (val) {
      if (val) {
        this.rules.parent_id = [
          {
            required: true,
            message: '请选择上级结构',
            trigger: 'change',
          },
        ]
      }
    },
    height: function (Val) {
      console.log(val, '4546465456')
      this.height = val + 'px'
    },
  },
}
</script>

<style scoped lang='scss'>
::v-deep {
  .jgTree {
    .el-tree-node {
      .el-tree-node__content {
        padding: 10px 20px;
        border-bottom: 1px solid #ebeef5;
      }
    }
  }

  .tableButton {
    padding: 0;
    font-size: 14px;
  }

  .el-table .cell.el-tooltip {
    text-align: left;
  }

  .retable {
    margin-top: 20px;
  }

  .el-button--info.is-disabled {
    background-color: #dcdfe6;
    border-color: #dcdfe6;
  }

  .el-icon-editBox {
    margin-left: 0.5rem;
  }

  .el-icon-deleteBox {
    margin-left: 0.5rem;
  }

  .custom-tree-node {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    padding-right: 8px;
  }

  .statusTips {
    display: inline-block;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    margin-right: 0.5rem;
  }

  .statusTips.yellow {
    background-color: #e6a23c;
  }

  .statusTips.green {
    background-color: #67c23a;
  }

  .statusTips.red {
    background-color: #f56c6c;
  }
}

.left {
  border: 1px solid #ebeef5;
  margin-top: 20px;

  .title {
    text-align: center;
    background-color: #fff;
    margin: 0;
    padding: 10px 0;
    border-bottom: 1px solid #ebeef5;
    font-weight: bold;
    background-color: #f4f5f9;
    cursor: pointer;
  }
}

.formarea {
  margin-top: 20px;
  margin-left: 2rem;

  .el-form {
    margin-top: 20px;
  }
}

.pos {
  position: absolute;
  left: 0;
  top: 0;
}

.edittext {
  margin: 0 5px;
  color: #4c68ef;
  cursor: pointer;
}

.content {
  .left {
    overflow-y: visible;
    overflow-x: hidden;
  }
}
</style>
